package com.fwtai.web;

import com.fwtai.bean.PageFormData;
import com.fwtai.datasource.DaoHandle;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;

/**
 * 门店访问数据库
 * @作者 李宇鹏
 * @版本 v1.0
 * @创建时间 2023-03-13 16:30:23
 * @QQ号码 444141300
 * @Email service@yinlz.com
 * @官网 <url>http://www.fwtai.com</url>
*/
@Repository
public class StoreDao{

  private final DaoHandle dao;

  public StoreDao(final DaoHandle dao){
    this.dao = dao;
  }

  public int add(final PageFormData formData){
    return dao.execute("store.add",formData);
  }

  public HashMap<String,String> queryExistById(final long kid){
    return dao.queryForHashMapString("store.queryExistById",kid);
  }

  public List<HashMap<String,String>> queryFiles(final long[] lists){
    return dao.queryForListString("store.queryFiles",lists);
  }

  public int edit(final PageFormData formData){
    return dao.execute("store.edit",formData);
  }

  public HashMap<String,Object> queryById(final long kid){//当是long类型时就不能传null空值,否则报空指针
    return dao.queryForHashMap("store.queryById",kid);
  }

  public int delById(final long kid){//当是long类型时就不能传null空值,否则报空指针
    return dao.execute("store.delById",kid);
  }

  public int delByKeys(final long[] list){
    return dao.execute("store.delByKeys",list);
  }

  //查询数据是否已被别的关联表使用,list不允许为空
  public Long queryIsUsed(final Long... kids){
    return dao.queryForLong("store.queryIsUsed",kids);
  }

  public List<HashMap<String,Object>> getListData(final PageFormData formData){
    return dao.queryForListHashMap("store.listData",formData);
  }

  public Integer getListTotal(final PageFormData formData){
    return dao.queryForInteger("store.listTotal",formData);
  }

  public int editAuth2(final PageFormData formData){
    return dao.execute("store.editAuth",formData);
  }

  @Transactional
  public int editAuthCode(final PageFormData formData){
    dao.execute("partner.updateInvitationCode",formData);
    return dao.execute("store.editAuth",formData);
  }

  public int editAuth(final PageFormData formData){
    return dao.execute("store.editAuth",formData);
  }
}